﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace ZG_member
{
    public partial class CourseAdd : Form
    {
        public CourseAdd(CourseStage cs)
        {
            InitializeComponent();
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            this.Opacity = 0;
            csForm = cs;
        }




        public CourseAdd(ZG_member.Model.CourseStage cour,CourseStage cs)
        {
            InitializeComponent();
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            this.Opacity = 0;
            courseMod = cour;
            csForm = cs;
            this.Text = "修改阶段";
        }
        ZG_member.Model.CourseStage courseMod;
        CourseStage csForm;
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Left += 2;
            this.Opacity += 0.1;
            if (Opacity == 1)
            {
                this.timer1.Stop();

            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer2.Stop();
                this.Close();
            }
        }
        int flag = 0;
        private void CourseAdd_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag == 0)
            {
                e.Cancel = true;
                flag = 1;
                this.timer2.Start();
            }
        }

        private void CourseAdd_Load(object sender, EventArgs e)
        {
            timer1.Start();
            if (courseMod != null)
            {
                this.textBox1.Text = courseMod.StageName;
                this.textBox2.Text = courseMod.StageContent;

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
             ZG_member.BLL.CourseStage course = new ZG_member.BLL.CourseStage();

            if (this.Text != "修改阶段")
            {
                ZG_member.Model.CourseStage courseMode = new ZG_member.Model.CourseStage();
                string biaoti = this.textBox1.Text;
                string neirong = this.textBox2.Text;
                courseMode.StageName = biaoti;
                courseMode.StageContent = neirong;
                course.add(courseMode);
                MessageBox.Show("添加成功");
        
            }
            else
            {
                courseMod.StageName = this.textBox1.Text;
                courseMod.StageContent = this.textBox2.Text;
                course.Update(courseMod);
                MessageBox.Show("修改成功");
                this.Close();
            }
            csForm.dataGridView1.DataSource = course.GetListWhere("").Tables[0];
            this.Close();
        }
    }
}
